package com.jdb.social.provider.service.impl;

import com.guns21.common.util.DateUtils;
import com.guns21.common.uuid.ID;
import com.guns21.result.domain.Result;
import com.guns21.support.service.BaseCommandService;
import com.jdb.social.provider.entity.FavoriteDO;
import com.jdb.social.provider.repository.FavoriteRepository;
import com.jdb.social.provider.service.FavoriteCommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class FavoriteCommandServiceImpl extends BaseCommandService implements FavoriteCommandService {

    @Autowired
    private FavoriteRepository favoriteRepository;

    @Override
    public Result createFavorite(String userId, String referenceId, Byte type, boolean favorite) {
        if (favorite) {
            FavoriteDO favoriteDO = FavoriteDO.newInstance();
            favoriteDO.setUserId(userId);
            favoriteDO.setReferenceId(referenceId);
            favoriteDO.setType(type);
            favoriteDO.setId(ID.get());
            favoriteDO.setGmtCreate(LocalDateTime.now());
            favoriteRepository.save(favoriteDO);
        } else {
//            favoriteRepository.deleteyUserIdAndReferenceIdAndType(userId,referenceId,type);
        }
        return Result.success();
    }
}
